<%@page contentType="text/html"%>  
<%@page pageEncoding="UTF-8"%>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>  
<%@taglib uri="http://richfaces.org/a4j" prefix="a4j"%>  
<%@taglib uri="http://richfaces.org/rich" prefix="rich"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"   
"http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <title>Impressão de Venda</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta http-equiv="Pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="cache-control" content="no-store">
        <meta http-equiv="expires" content="0">
        <style type="text/css"><!--@import url("../_css/style.css");--></style>
        <style type="text/css">
            .recibo{
                font-family:tahoma;
                font-size:11px;
            }
            .reciboSmall{
                font-family:tahoma;
                font-size:9px;
            }
        </style>
        <script type="text/javascript" language="javascript">
            function imprimir() {
                document.getElementById("botoes").style.display = "none";
                self.print();
                document.getElementById("botoes").style.display = "inline";
            }
        </script>
    </head>
    <body>
        <c:set var="total" value="0"/>
        <f:view>
            <t:saveState id="_bean" value="#{VendaBean}" />
            <h:form>
                <table width="350" border="0" class="recibo" cellpadding="0" cellspacing="0">
                    <tr>
                        <td colspan="5" align="center"><strong>VENDA Cód. ${VendaBean.id}</strong></td>
                    </tr>
                    <tr>
                        <td style="border-bottom: 1pt solid;" colspan="2"><strong>Produto(s)</strong></td>
                        <td style="border-bottom: 1pt solid;" colspan="3">&nbsp;</td>
                    </tr>
                    <tr>
                        <td width="10%" style="border-bottom: 1pt solid;" nowrap>Cód Pro</td>
                        <td width="45%" style="border-bottom: 1pt solid;">Descrição</td>
                        <td width="10%" style="border-bottom: 1pt solid;">Qtd</td>
                        <td width="15%" style="border-bottom: 1pt solid;" align="right">Vlr Unit</td>
                        <td width="15%" style="border-bottom: 1pt solid;" align="right">Vlr Total</td>
                    </tr>
                <c:forEach items="${VendaBean.listaVendaItems}" var="lvit" varStatus="stt">
                    <tr>
                        <td>${lvit.produto.id}</td>
                        <td>${lvit.produto.descricao}</td>
                        <td>${lvit.quantidade}</td>
                        <td align="right"><fmt:formatNumber maxFractionDigits="2" pattern="#,##0.00" value="${lvit.valorUnitario}"/></td>
                        <td align="right"><fmt:formatNumber maxFractionDigits="2" pattern="#,##0.00" value="${lvit.valorTotal}"/></td>
                    </tr>
                    <c:set var="total" value="${total+lvit.valorTotal}"/>
                </c:forEach>
                    <tr>
                        <td colspan="4" align="right" style="border-top: 1pt solid;">Total&nbsp;</td>
                        <td style="border-top: 1pt solid;" align="right"><fmt:formatNumber maxFractionDigits="2" pattern="#,##0.00" value="${total}"/></td>
                    </tr>
                    <c:set var="total" value="0"/>
                    <tr>
                        <td style="border-bottom: 1pt solid;" colspan="2"><strong>Pagamento(s)</strong></td>
                        <td style="border-bottom: 1pt solid;" colspan="2">&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td style="border-bottom: 1pt solid;">Parc</td>
                        <td style="border-bottom: 1pt solid;">Forma Pagamento</td>
                        <td style="border-bottom: 1pt solid;">Vencimento</td>
                        <td style="border-bottom: 1pt solid;" align="right" nowrap>Valor Parc</td>
                    </tr>
                <c:forEach items="${VendaBean.listaVendaLancamentos}" var="lfp" varStatus="stt">
                    <tr>
                        <td>${lfp.numParcela}</td>
                        <td>${lfp.formaPagamento.descricao}</td>
                        <td><fmt:formatDate pattern="dd/MM/yyyy" value="${lfp.dataVencimento}"/>&nbsp;</td>
                        <td align="right"><fmt:formatNumber maxFractionDigits="2" pattern="#,##0.00" value="${lfp.valor}"/></td>
                    </tr>
                    <c:set var="total" value="${total+lfp.valor}"/>
                </c:forEach>
                    <tr>
                        <td colspan="3" align="right" style="border-top: 1pt solid;">Total&nbsp;</td>
                        <td style="border-top: 1pt solid;" align="right"><fmt:formatNumber maxFractionDigits="2" pattern="#,##0.00" value="${total}"/></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                    </tr>
                </table>
                <br><br>
                <div id="botoes">
                    <h:commandButton value="Imprimir" onclick="javascript:imprimir();"/>&nbsp;&nbsp;
                    <h:commandButton value="Retornar" action="#{VendaBean.retornar}"/>
                </div>
            </h:form>
        </f:view>
    </body>
</html>